***File used to compute Decay rate figure for Murphy et al. "Chatting at Church: Information Diffusion through Religious Networks"


clear all
macro drop _all


global user "[INSERT PATH HERE]"
cd "${user}"

***Appendix figure A1***

mat f=J(108,1,.)
quietly{
forvalues z=1/1000{

use church_indv_membership, clear
set seed `z'
gen random=runiform(0,1)
sort villagenum random
by villagenum: gen villid = _n
gen villid2=villid^2

tab ownchurchid, gen(churchid)
gen newchurch=.
order newchurch, after(villid)
egen villcount=count(indvid), by(villagenum)

forvalues x=1/194{
gen churchidnew`x'=sum(churchid`x')
replace newchurch=1 if churchidnew`x'==1&churchidnew`x'[_n-1]==0
}
replace newchurch=0 if newchurch==.

reg newchurch i.villid


mat B=e(b)
mat d=J(1,108,.)
local c=_b[_cons]
forvalues x=1/108{
mat d[1,`x']=`c'+B[1,`x']
}

mat e=J(108,1,.)
forvalues x=1/108{
mat e[`x',1]=d[1,`x']
}

mat f=f, e
}
}
svmat f
egen rowmean=rowmean(f2-f1001)
gen n=_n
replace n=. if n>108

twoway scatter rowmean n, ytitle(Probability of new church mentioned) xtitle(nth individual in village)
graph export "decayscatter.png", as(png) replace


twoway lpolyci rowmean n, ytitle(Probability of new church mentioned) xtitle(nth individual in village) legend(lab(1 "95% Confidence Interval") lab(2 "Kernal-weighted Polynomial Smoothing")  size(small))
graph export "decaylpolyci.png", as(png) replace
